package com.dlm.service.impl;

import com.dlm.dao.Evaluate;
import com.dlm.dao.Technician;
import com.dlm.service.IEvaluateService;
import com.dlm.service.ITechnicianService;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * Created by chongsong on 15/2/1.
 * <mailto>chong.song@autonavi.com</mailto>
 */
public class EvaluateServiceImpl implements IEvaluateService {
    @Override
    public boolean add(Evaluate evaluate) throws Exception {
        return evaluate.save();
    }

    @Override
    public boolean delete(long id) throws Exception {
        return Evaluate.dao.deleteById(id);
    }

    @Override
    public boolean update(Evaluate evaluate) throws Exception {
        return evaluate.update();
    }

    @Override
    public Evaluate findById(long id) throws Exception {
        return Evaluate.dao.findById(id);
    }

    @Override
    public Page<Evaluate> findByPage(int pn,int ps) throws Exception {
        String select = "select *";
        String from = "from evaluate";
        Object[] param = {};
        return Evaluate.dao.paginate(pn, ps, select, from, param);
    }

    @Override
    public Evaluate findDeg(long techId) throws Exception {
        String sql = "select tech_id,avg(pd) as pd,avg(cd) as cd ,avg(td) as td,sum(ada) as ada,sum(adb) as adb,sum(adc) as adc from evaluate where tech_id = " + techId;
        return Evaluate.dao.findFirst(sql);
    }
}
